package approve.adapter;

import java.util.ArrayList;

import model.pojo.Employee;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import approve.action.App_ViewForm12;
import approve.action.App_ViewForm13;
import approve.action.App_ViewForm14;
import approve.action.App_ViewForm15;
import approve.action.App_ViewForm16;
import approve.action.App_ViewForm17;
import approve.action.App_ViewForm_LessThan10;
import approve.action.R;

public class App_Adapter_AddRefer extends BaseAdapter{

	Context context;
	ArrayList<Employee> listrefer= new ArrayList<Employee>();
	String strid;
	int flagviewform;
	ViewHolder holder;
	public App_Adapter_AddRefer(App_ViewForm_LessThan10 context, ArrayList<Employee> lst, int flagviewform){
		this.context=context;
		this.listrefer=lst;
		this.flagviewform=flagviewform;
	}
	
	public App_Adapter_AddRefer(App_ViewForm12 context, ArrayList<Employee> lst, int flagviewform){
		this.context=context;
		this.listrefer=lst;
		this.flagviewform=flagviewform;
	}
	
	public App_Adapter_AddRefer(App_ViewForm13 context, ArrayList<Employee> lst, int flagviewform){
		this.context=context;
		this.listrefer=lst;
		this.flagviewform=flagviewform;
	}
	
	public App_Adapter_AddRefer(App_ViewForm14 context, ArrayList<Employee> lst, int flagviewform){
		this.context=context;
		this.listrefer=lst;
		this.flagviewform=flagviewform;
	}
	
	public App_Adapter_AddRefer(App_ViewForm15 context, ArrayList<Employee> lst, int flagviewform){
		this.context=context;
		this.listrefer=lst;
		this.flagviewform=flagviewform;
	}
	
	public App_Adapter_AddRefer(App_ViewForm16 context, ArrayList<Employee> lst, int flagviewform){
		this.context=context;
		this.listrefer=lst;
		this.flagviewform=flagviewform;
	}
	
	public App_Adapter_AddRefer(App_ViewForm17 context, ArrayList<Employee> lst, int flagviewform){
		this.context=context;
		this.listrefer=lst;
		this.flagviewform=flagviewform;
	}
	
	@Override
	public int getCount() {
		return listrefer.size();
	}

	@Override
	public Object getItem(int position) {
		return listrefer.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Employee em=listrefer.get(position);
		
		if(convertView==null){
			holder = new ViewHolder();
			
			LayoutInflater a=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = a.inflate(R.layout.adapter_list_approver, parent,false);
			holder.nameview=(TextView)convertView.findViewById(R.id.txtemp11);
			holder.imiview=(ImageView)convertView.findViewById(R.id.imageDeleteEmp11);
			
			convertView.setTag(holder);
		}
		else{
			holder = (ViewHolder)convertView.getTag();
		}
		
		holder.nameview.setText(em.getFullName());
		
		holder.imiview.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				listrefer.remove(em);
				if(flagviewform==10){
					((App_ViewForm_LessThan10)context).getReferlist();
					((App_ViewForm_LessThan10)context).getReferadapter().notifyDataSetChanged();
				}else if(flagviewform==12){
					((App_ViewForm12)context).getReferlist();
					((App_ViewForm12)context).getReferadapter().notifyDataSetChanged();
				}else if(flagviewform==13){
					((App_ViewForm13)context).getReferlist();
					((App_ViewForm13)context).getReferadapter().notifyDataSetChanged();
				}else if(flagviewform==14){
					((App_ViewForm14)context).getReferlist();
					((App_ViewForm14)context).getReferadapter().notifyDataSetChanged();
				}else if(flagviewform==15){
					((App_ViewForm15)context).getReferlist();
					((App_ViewForm15)context).getReferadapter().notifyDataSetChanged();
				}else if(flagviewform==16){
					((App_ViewForm16)context).getReferlist();
					((App_ViewForm16)context).getReferadapter().notifyDataSetChanged();
				}else if(flagviewform==17){
					((App_ViewForm17)context).getReferlist();
					((App_ViewForm17)context).getReferadapter().notifyDataSetChanged();
				}
			}
		});
		
		return convertView;
	}

	public ArrayList<Employee> getListrefer() {
		return listrefer;
	}

	public void setListrefer(ArrayList<Employee> listrefer) {
		this.listrefer = listrefer;
	}

	public String getStrid() {
		strid="";
		if(listrefer!=null && listrefer.size()>0){
			for(int i=0;i<listrefer.size();i++){
				if(strid.equals("")){
					strid="'"+listrefer.get(i).getIdemployee()+"'";
				}else{
					strid+=",'"+listrefer.get(i).getIdemployee()+"'";
				}
			}
		}
		return strid;
	}

	public void setStrid(String strid) {
		this.strid = strid;
	}

	public static class ViewHolder{
		TextView nameview;
		ImageView imiview;
	}
}
